package day0328;

import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        //1.
        String generateVerifyCode=Test4.generate(5);
        System.out.println(generateVerifyCode);
        //2.
        Scanner s=new Scanner(System.in);
        System.out.println("请输入验证码：");
        String userInputVerifyCode=s.nextLine();
        //3.
        String rs=Test4.judgeIsRight(generateVerifyCode,userInputVerifyCode);
        System.out.println(rs);
    }

    /**
     * @Param gvc 是生成的验证码
     * @Param uivc是用户输入的验证码
     * return boolean类型的结果(表示两个验证码是否相同)
     * 本方法是用来比较  gv和uivc是否相等的(判断俩验证码是否相同)
     */
    public static String judgeIsRight(String gvc,  String uivc) {
        if(gvc.equals(uivc)){
            return "验证码正确";
        }else{
            return "验证码错误";
        }
    }


    public static  String generate(int count) {
        String strs="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        //1.先取出一个字符放入rs中
        String rs=strs.charAt(  (int)(Math.random()*strs.length()) )+"";
        if(count==0){
            rs="";
        }
        for (int i = 0; i < count-1; i++) {//i=0,1,2
            String letter=strs.charAt(  (int)(Math.random()*strs.length()) )+"";
            rs=rs+letter;
        }
        return  rs;
    }
}
